package com.hc.comm.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
* @author
* @date 2015年12月25日 下午8:35:27
*/
@Component
public class SpringUtils implements ApplicationContextAware {

	private static ApplicationContext applicationContext;
	
	/* 
	* @param applicationContext
	* @throws BeansException
	* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	*/
	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		SpringUtils.applicationContext = applicationContext;
	}
	
	
	/** 
     * 获取对象 
     * @param name 
     * @return Object
     * @throws BeansException 
     */  
    public static Object getBean(String name) throws BeansException {  
        return applicationContext.getBean(name);  
    }
    
    
    /** 
     * 获取对象 
     * @param name 
     * @return Object
     * @throws BeansException 
     */  
    @SuppressWarnings({ "rawtypes", "unchecked" })
	public static Object getBean(Class cls) throws BeansException {  
        return applicationContext.getBean(cls);  
    }

}
